package com.ruoyi.web.controller.dmpdatacollect;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dmpdatacollect.domain.DmpDcollectDs;
import com.ruoyi.dmpdatacollect.service.IDmpDcollectDsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据采集源Controller
 * 
 * @author MquanZeng
 * @date 2021-12-16
 */
@RestController
@RequestMapping("/dmpdatacollect/datasource")
public class DmpDcollectDsController extends BaseController
{
    @Autowired
    private IDmpDcollectDsService dmpDcollectDsService;

    /**
     * 查询数据采集源列表
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:datasource:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmpDcollectDs dmpDcollectDs)
    {
        startPage();
        List<DmpDcollectDs> list = dmpDcollectDsService.selectDmpDcollectDsList(dmpDcollectDs);
        return getDataTable(list);
    }

    /**
     * 导出数据采集源列表
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:datasource:export')")
    @Log(title = "数据采集源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmpDcollectDs dmpDcollectDs)
    {
        List<DmpDcollectDs> list = dmpDcollectDsService.selectDmpDcollectDsList(dmpDcollectDs);
        ExcelUtil<DmpDcollectDs> util = new ExcelUtil<DmpDcollectDs>(DmpDcollectDs.class);
        util.exportExcel(response, list, "数据采集源数据");
    }

    /**
     * 获取数据采集源详细信息
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:datasource:query')")
    @GetMapping(value = "/{dsId}")
    public AjaxResult getInfo(@PathVariable("dsId") Integer dsId)
    {
        return AjaxResult.success(dmpDcollectDsService.selectDmpDcollectDsByDsId(dsId));
    }

    /**
     * 新增数据采集源
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:datasource:add')")
    @Log(title = "数据采集源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmpDcollectDs dmpDcollectDs)
    {
        return toAjax(dmpDcollectDsService.insertDmpDcollectDs(dmpDcollectDs));
    }

    /**
     * 修改数据采集源
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:datasource:edit')")
    @Log(title = "数据采集源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmpDcollectDs dmpDcollectDs)
    {
        return toAjax(dmpDcollectDsService.updateDmpDcollectDs(dmpDcollectDs));
    }

    /**
     * 删除数据采集源
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:datasource:remove')")
    @Log(title = "数据采集源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dsIds}")
    public AjaxResult remove(@PathVariable Integer[] dsIds)
    {
        return toAjax(dmpDcollectDsService.deleteDmpDcollectDsByDsIds(dsIds));
    }

    /**
     * 复制数据采集源
     */
    @PreAuthorize("@ss.hasPermi('dmpdatacollect:datasource:copy')")
	@GetMapping("/copy/{dsId}")
    public AjaxResult copyDatasource(@PathVariable Integer dsId)
    {
        return dmpDcollectDsService.copyDatasource(dsId);
    }

    /**
     * 获取数据采集源下拉项
     */
    @GetMapping("/selectOptions")
    public AjaxResult selectOptions()
    {
        return AjaxResult.success(dmpDcollectDsService.getSelectOptionsList());
    }
}
